#ifndef __FORMEDITORW_H_
#define __FORMEDITORW_H_

#include <qdesigner_components.h>
#include <abstractformwindowmanager.h>
#include <abstractformeditor.h>
#include <abstractpropertyeditor.h>
#include <abstractwidgetbox.h>

#include "private/qdesigner_integration_p.h"

class ObjectInspectorW;
class PropertyEditorW;
class WidgetBoxW;
class ActionEditorW;
class SignalSlotEditorW;
class ResourceEditorW;
class FormWindowW;

class FormEditorW : public QObject
{
    Q_OBJECT
public:
    enum DesignerAction
	{
        // 集成的
        ActionCut = 0,
        ActionCopy = 1,
        ActionPaste = 2,
        ActionDelete = 3,
        ActionSelectAll = 4,
        ActionUndo = 5,
        ActionRedo = 6,

        // 附加的
        ActionLower = 7,
        ActionRaise = 8,
        ActionHorizontalLayout = 9,
        ActionVerticalLayout = 10,
        ActionSplitHorizontal = 11,
        ActionSplitVertical = 12,
        ActionGridLayout = 13,
        ActionBreakLayout = 14,
        ActionAdjustSize = 15,
        LastStaticAction = 15
    };

    FormEditorW(QObject *parent = 0);
    virtual ~FormEditorW();

    static FormEditorW *instance();
    QAction *idToAction(int id);

    bool updateTopLevel(QWidget *delWidget = 0);
    inline QDesignerFormEditorInterface *formEditor() const { return m_formeditor; }

    inline QWidget *signalSlotEditor() const { return m_designerSignalSlotEditor; }
    inline void setDesignerSignalSlotEditor(QWidget *w) { m_designerSignalSlotEditor = w; }

    inline int lastAction() { return LastStaticAction + m_previewActions.size(); }

    bool eventFilter(QObject *, QEvent *);

    void initPlugins();
    QString pluginFailureString() const;
    bool initializeJambiPlugins(const QString &jambiBase, const QString &jambiPluginPath, const QString &customWidgetClassPath, const QString &resourcePath, const QString &jvm);
    void setPluginPath(const QString &pluginPath);

    void setResourceEditor(ResourceEditorW *resourceEditor)
    {
        m_resourceEditor = resourceEditor;
    }

    void setObjectInspector(ObjectInspectorW *objectInspector)
    {
        m_objectInspector = objectInspector;
    }

    void setPropertyEditor(PropertyEditorW *propertyEditor)
    {
        m_propertyEditor = propertyEditor;
    }

    void setWidgetBox(WidgetBoxW *widgetBox)
    {
        m_widgetBox = widgetBox;
    }

    void setActionEditor(ActionEditorW *actionEditor)
    {
        m_actionEditor = actionEditor;
    }

    void setSignalSlotEditor(SignalSlotEditorW *signalSlotEditor)
    {
        m_signalSlotEditor = signalSlotEditor;
    }

    void initialize();

    void addFormWindowW(FormWindowW *formWindowW);
    void removeFormWindowW(FormWindowW *formWindowW);
    FormWindowW *activeFormWindowW() const;

Q_SIGNALS:
    void updateCustomWidgetPlugins();

public Q_SLOTS:
    void activeFormWindowChanged(QDesignerFormWindowInterface *);

private Q_SLOTS:
    void preview(const QString &);

private:
    void initializeCorePlugins();
    void setupPreviewActions();
    static FormEditorW *m_self;
    QDesignerFormEditorInterface *m_formeditor;
    QWidget *m_designerSignalSlotEditor;
    QList<QAction *> m_previewActions;

    QString m_jambiPluginPath;

    ObjectInspectorW *m_objectInspector;
    PropertyEditorW *m_propertyEditor;
    WidgetBoxW *m_widgetBox;
    ActionEditorW *m_actionEditor;
    SignalSlotEditorW *m_signalSlotEditor;
    ResourceEditorW *m_resourceEditor;

    QList<FormWindowW *> m_formWindows;

    QString m_pluginFailureString;

    uint m_initialized : 1;
};

class ActionChangedNotifier : public QObject
{
    Q_OBJECT
public:
    ActionChangedNotifier(QObject *parent, int id);

public Q_SLOTS:
    void actionChanged();

private:
    int actId;
};

#endif //__FORMEDITORW_H_
